package com.example.FirstBook.adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

public class ImageViewpageAdapter extends PagerAdapter {
    List<ImageView> viewList;
    public ImageViewpageAdapter(List<ImageView> viewList){
        this.viewList = viewList;
    }
    @Override
    public int getCount() {
        return Integer.MAX_VALUE; // 要无限轮播
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ViewParent parent = container.getParent();
        if(parent!=null)
            Log.d("who_are_you",parent.getClass().toString());
        container.addView(viewList.get(position%viewList.size()));//让他永远在01234
        return viewList.get(position%viewList.size());
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(viewList.get(position%viewList.size()));
    }
}

